package com.atguigu.flinksql;

import org.apache.flink.configuration.Configuration;
import org.apache.flink.streaming.api.datastream.DataStreamSource;
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;
import org.apache.flink.table.api.Table;
import org.apache.flink.table.api.bridge.java.StreamTableEnvironment;

import static org.apache.flink.table.api.Expressions.$;

public class Flink03_Table_BaseUse_Tuple {
    public static void main(String[] args) {
        Configuration configuration = new Configuration();
        configuration.setInteger("rest.port", 10000);
        StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment(configuration);
        env.setParallelism(2);

        //创建流
        DataStreamSource<Integer> stream = env.fromElements(1, 10, 30, 20, 13, 24);

        //1、创建表环境
        StreamTableEnvironment tEnv = StreamTableEnvironment.create(env);

        //2、创建表,顺便指定表的结构，即表的字段名称等！
        Table table = tEnv.fromDataStream(stream, $("a"));

        //输出表结构信息
        table.printSchema();

        //输出
        table.select($("a")).execute().print();

    }
}
